#coding=utf-8
'''
本模块主要是属性概念的定义
'''

class Dimension(object):
    def __init__(self):
        '''
            首先要定义一个维度对象对应的属性：
            维度的名称：name
            维度的标签名称：label
            维度的描述：desc
            维度来自于哪个库：dbname
            维度来自于哪个表：tbname
            维度来自于哪个字段：colname
        '''
        pass

#from operator import itemgetter
#
#class Dimension(object):
#    def __init__(self, **kwargs):
#        for key, value in kwargs.items():
#            setattr(self, key, value)
#    
#    def parse(self):
#        ordinal_getter = itemgetter('table', 'field')
#        table_list, selected_fields = [[] for _ in range(2)]
#        for item in self.measures:
#            if item['table'] not in table_list:
#                table_list.append(item['table'])
#            if item['field'].find('(') == -1:
#                selected_fields.append('.'.join(ordinal_getter(item)))
#            else:
#                selected_fields.append(item['field'])
#        selected_str = ','.join(selected_fields)
#        
#        _select = 'select %s ' % selected_str
#        _from = 'from %s' % table_list[0]
#        _where = 'where %s.ds = "2011-08-22"' % table_list[0]   
#        print '%s \n%s \n%s' % (_select, _from, _where)
#            
#
#if __name__ == '__main__':
#    dimension_config = {'name':'user_property',
#                        'desc':'Basic information about the users',
#                        'data_limit_by':{'x':['ds'], '':[]}, 
#                        'measures':[{'table':'x', 'field':'xfield', 'name':'A Test Measure'},
#                                    {'table':'farm_user_gameinfo', 'field':'sex', 'name':'性别'},
#                                    {'table':'farm_user_gameinfo', 'field':'date_sub(from_unixtime(unix_timestamp()), farm_user_gameinfo.birthday)', 'name':'年龄'},
#                                    {'table':'farm_user_gameinfo', 'field':'add_time', 'name':'注册时间'},
#                                    ]}
#    d = Dimension(**dimension_config)
#    d.parse()
        